<template>
	<view class="main">
		<!-- #ifdef MP-WEIXIN -->
		<image class="bg" src="@/static/img/image3.png" mode="widthFix"></image>
		<!-- #endif -->
		<view class="header">
			<view class="top">
				<text>可提总数</text>
				<view class="btn" @click="toTake">提货</view>
			</view>
			<text>{{totalNumber}}</text>
		</view>
		<view class="list">
			<view class="tit">
				提货记录
			</view>
			<view class="itemBox">
				<u-empty v-if="list.length == 0" text="暂无记录" mode="data"
					icon="http://cdn.uviewui.com/uview/empty/data.png">
				</u-empty>
				<view class="item" v-for="(item,index) in list" :key="index">
					<view class="left">
						<text>总数量：{{item.number}}</text>
						<text>{{item.createtime}}</text>
						<view class="childList" v-for="(citem,index) in item.ids" :key="index">
							<view class="detialImgBox">
								<img :src="citem.image" class="img" style="width: 120rpx; height: 120rpx;margin-bottom:40rpx;"></img>
								<text style="margin-left: 20rpx;">{{citem.name}}提取{{citem.number}}件</text>
							</view>
							
						</view>
					</view>
					<view class="right">
						<text>{{item.status_text}}</text>	
					</view>
				</view>
			</view>
		</view>
		
		<u-popup :show="show" mode="center" @close="show = false">
			<view class="popup">
				<view class="title">数量</view>
				<input type="number" v-model="number" placeholder="0" />
				<view class="title">留言</view>
				<u--textarea v-model="message" placeholder="请输入留言" autoHeight ></u--textarea>
				
				<view class="bottom">
					<view class="btn cancel" @click="show = false, number = 0, message = ''">取消</view>
					<view class="btn confirm" @click="handleConfirm">确认</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		user,
		staticLists,
		productLists,
		productCreate
	} from '@/api/index.js'
	export default {
		data() {
			return {
				info: {},
				list: [],
				page: 1,
				last_page: null,
				show: false,
				number: 0,
				message: '',
				totalNumber:0
			}
		},
		onReachBottom() {
			if (this.page == this.last_page) {
				uni.showToast({
					title: '已经是最后一页了',
					icon: 'none'
				})
			} else {
				this.page++
				this.getList()
			}
		},
		onShow() {
			this.getInfo()
			this.getList()
		},
		methods: {
			async getList() {
				if (this.page == 1) {
					this.list = []
				}
				let res = await productLists({
					page: this.page
				})
				console.log('res',res);
				res.data.data.forEach(item => {
					this.list.push(item)
				})
				this.total = res.data.total
				this.last_page = res.data.last_page
			},
			
			async getInfo() {
				let res = await user()
				this.info = res.data
				this.totalNumber = res.data.bonus_number
				
			},
			
			 toTake(){
				if(this.totalNumber == 0){
					uni.showToast({
						title: '可提数量为0',
						icon: 'none',
						duration:1500
					})
				}else{
					uni.navigateTo({
						url:"/pageC/takeSth"
					})
				}
				
			},
			
			async handleConfirm () {
				if (this.number > this.info.bonus_number) {
					uni.showToast({
						title: '数量不能大于可提总数',
						icon: 'none'
					})
					return
				}
				let res = await productCreate({
					number: this.number,
					message: this.message
				})
				uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.show = false;
				if (res.code == 1) {
					setTimeout(() => {
						this.page = 1
						this.getInfo()
						this.getList()
					}, 1200)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		position: relative;
		background-image: url('@/static/img/image3.png');
		background-size: 100% 604rpx;
		background-repeat: no-repeat;
		background-position: top left;
		min-height: 100vh;
		background-color: #f6f6f6;
		display: flex;
		flex-direction: column;
		.bg{
			width: 100%;
			top: 0;
			left: 0;
			position: absolute;
			// z-index: -1;
		}

		.header {
			position: relative;
			z-index: 10;
			padding: 110rpx 50rpx;
			display: flex;
			flex-direction: column;
			
			.top {
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
			
			.btn {
				width: fit-content;
				height: 60rpx;
				line-height: 60rpx;
				padding: 0 32rpx;
				font-size: 26rpx;
				font-weight: 600;
				color: #fff;
				border: 2rpx solid #fff;
				border-radius: 30rpx;
				box-sizing: border-box;
			}
		
			text:first-child {
				color: #DCFFCB;
				font-size: 32rpx;
				margin-bottom: 30rpx;
			}
		
			text:last-child {
				color: #fff;
				font-size: 64rpx;
			}
		}

		.list {
			position: relative;
			z-index: 10;
			flex: 1;
			padding: 40rpx;
			background-color: #fff;
			border-radius: 30rpx 30rpx 0 0;

			.tit {
				color: #ea504f;
				font-size: 32rpx;
				font-weight: 500;
				margin-bottom: 30rpx;
			}

			.itemBox {
				.item {
					display: flex;
					justify-content: space-between;
					// align-items: center;
					color: #000;
					// margin-bottom: 20rpx;
					padding: 24rpx 0;
					border-bottom: 1rpx solid #ddd;
					box-sizing: border-box;

					.left {
						display: flex;
						flex-direction: column;

						text {
							font-size: 32rpx;
							margin-bottom: 16rpx;
						}

						text:last-child {
							font-size: 26rpx;
							color: #666;
							margin-bottom: 0;
						}
					}

					.right {
						display: flex;
						// flex-direction: column;
						// font-weight: 700;
						
						text {
							font-size: 32rpx;
							margin-bottom: 16rpx;
						}
						
						.status {
							color: #ea504f;
							font-size: 26rpx;
							text-align: right;
							margin-bottom: 0;
						}
					}
				}
			}
		}
		
		.popup {
			width: 85vw;
			padding: 32rpx 32rpx;
			border-radius: 32rpx;
			background-color: #fff;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			align-items: center;
			
			.title {
				width: 100%;
				font-size: 32rpx;
				font-weight: 500;
				color: #000;
				margin-bottom: 24rpx;
			}
			
			input {
				width: 100%;
				height: 92rpx;
				background-color: #F6F6F6;
				padding: 0 24rpx;
				border-radius: 16rpx;
				box-sizing: border-box;
				margin-bottom: 24rpx;
			}
			
			
			
			.bottom {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				gap: 24rpx;
				margin-top: 60rpx;
			}
			
			.btn {
				width: fit-content;
				flex: 1;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				color: #2F2F2F;
				font-size: 32rpx;
				border: 1rpx solid #A0A0A0;
				border-radius: 40rpx;
				box-sizing: border-box;
			}
			
			.confirm {
				color: #fff;
				background-color: #ea504f;
				border: 0;
			}
		}
	}
	
	::v-deep .u-textarea {
		width: 100%;
	}
	
	.childList{
		display: flex;
	}
	
	.detialImgBox{
		
	}
</style>